package com.itheima.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 死信队列配置
 * @author 张文接
 * @version 1.0
 * @createTime 2024/9/23 17:07
 */
@Configuration
public class NormalConfig {
    @Bean
    public DirectExchange normalExchange() {
        return new DirectExchange("normal.direct");
    }

    /**
     * 创建一个名为 "normal.queue" 的持久化队列，并将其配置为使用 "dlx.direct" 作为死信交换机
     *
     * @return 一个新的 Queue 对象
     */
    @Bean
    public Queue normalQueue() {
        return QueueBuilder
                .durable("normal.queue")
                .deadLetterExchange("dlx.direct")
                .build();
    }

    @Bean
    public Binding normalExchangeBinding(DirectExchange normalExchange, Queue normalQueue) {
        return BindingBuilder
                .bind(normalQueue)
                .to(normalExchange)
                .with("hi");
    }
}
